<?php
namespace app\wxapp\controller;
use app\common\entity\Result;
use app\Request;
use app\common\service\CategoryService;
use app\wxapp\service\WechatUserService;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/4 0004
 * Time: 19:51
 */
class Category extends Base {
    //取出所有的分类目录
    public function all(){
        $service = new CategoryService();
        $data =  $service->all();
        return Result::success($data);
    }

    /**
     *
     */
    public function tree(){
        $service = new CategoryService();
        $tree = $service->tree();
        return Result::success($tree);
    }

    /**
     * 用户已经设置的选中状态 目前初始状态 为全部选中
     */
    public function selected(){
        $service = new WechatUserService();
        $res = $service -> getSelectedCategory($this->user['id']);
        return Result::success($res);
    }

    /**
     * 偏好设置
     * @param Request $request
     * @return \think\Response
     */
    public function select(Request $request){
        $data = $request->post();
        $service = new WechatUserService();
        $service->saveSelectedCategory($data,$this->user);
        return Result::success([]);
    }


    /**
     * @param Request $request
     * @return mixed
     */
    public function videoAndTopic(Request $request){
        $data = $request->post();
        $service = new CategoryService();
        $result = $service->getNewest($data);
        return Result::success($result);
    }
}
